/**
 * 
 */
package com.qunar.crawler.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author tao.zhang
 */
public class UrlFrontier {

	private UrlFrontier() {
	}

	// private static BlockingQueue<String> urlQueue = new
	// ArrayBlockingQueue<String>(10000);

	private static ConcurrentLinkedQueue<String> urlQueue = new ConcurrentLinkedQueue<String>();

	private static UrlFrontier frontier = new UrlFrontier();

	public static UrlFrontier getInstance() {
		return frontier;
	}

	public String take() {
		return urlQueue.poll();

	}

	public boolean isEmpty() {
		return urlQueue.isEmpty();
	}

	public void put(List<String> tourUrls) {
		urlQueue.addAll(tourUrls);
	}

	public int size() {
		return urlQueue.size();
	}

	public static void fill() {

		urlQueue.clear();
		String urlBase = "http://117go.com/live_p";
		String urlEnd = ".html";

		List<String> urls = new ArrayList<String>();

		urls.add("http://117go.com/live.html");
		for (int i = 1; i <= 20000; i++) {
			urls.add(urlBase + i + urlEnd);
		}
		urlQueue.addAll(urls);
	}
}
